package com.wanxi.servlet.device;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.VO.DeviceVO;
import com.wanxi.VO.UserVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.impl.DeviceServiceImpl;
import com.wanxi.service.impl.UserServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : 林子淳
 * @create 2023/2/28 8:50
 */
//@WebServlet("/back/device/delete")
public class DeviceDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2、获取前端传到后端的值
        String id = req.getParameter("id");
        //3、封装数据
        DeviceVO deviceVO = new DeviceVO();
        deviceVO.setId(Tool.strToInt(id));
        //4、调用逻辑层
        DeviceServiceImpl deviceService = new DeviceServiceImpl();
        //5、得到逻辑层返回来的值
        ResultDTO delete = deviceService.delete(deviceVO);
        //6、把后端的值返回给前端
        resp.getWriter().println(JSONObject.toJSONString(delete));
    }
}
